import { DictTag } from "@/components/common/DictTag";
import { dealDataExcept } from "@/utils/common";
import { goodsCodeRend, goodsNameRend } from "@/utils/tableColumns";
import { getDrkCount } from "../../common";

export function useColumns() {
  const directcolumns: TableColumnList = [
    {
      type: "expand",
      slot: "expand",
      fixed: "left",
      width: "30px"
    },
    {
      label: "商品名称/规格名称",
      prop: "goodsName",
      minWidth: 230,
      align: "left",
      fixed: "left",
      cellRenderer: goodsNameRend
    },
    {
      label: "商品编码/规格编码",
      prop: "goodsCode",
      align: "left",
      width: 150,
      cellRenderer: goodsCodeRend
    },
    {
      label: "商品条码",
      prop: "barCode",
      width: 150,
      slot: "barCode"
    },
    {
      label: "入库商品数量",
      prop: "rksl",
      width: 160,
      cellRenderer: ({ row }) => (
        <el-input-number
          v-show={row.oriGoodsSpecList && row.oriGoodsSpecList.length == 1}
          min={1}
          step={1}
          step-strictly
          clearable
          placeholder="请输入"
          v-model={row.rksl}
          style="width: 100%"
        />
      )
    },
    {
      label: "供应商名称",
      prop: "supplierName",
      showOverflowTooltip: true,
      width: 200
    },
    {
      label: "操作",
      width: 100,
      align: "center",
      slot: "operation"
    }
  ];

  const directChildColumns: TableColumnList = [
    {
      label: "商品名称/规格名称",
      prop: "specName",
      width: 200,
      align: "left",
      slot: "specName"
    },
    {
      label: "商品编码/规格编码",
      prop: "specCode",
      align: "left",
      width: 150,
      slot: "specCode"
    },
    {
      label: "商品条码",
      prop: "barCode",
      width: 150,
      showOverflowTooltip: true
    },
    {
      label: "入库商品数量",
      prop: "rksl",
      width: 160,
      align: "center",
      cellRenderer: ({ row }) => (
        <el-input-number
          min={1}
          step={1}
          step-strictly
          clearable
          placeholder="请输入"
          v-model={row.rksl}
          style="width: 100%"
        />
      )
    },
    {
      label: "供应商名称",
      prop: "supplierName",
      showOverflowTooltip: true,
      minWidth: 300,
      formatter: ({ supplierName }) => supplierName || "--"
    },
    {
      label: "操作",
      width: 100,
      align: "center",
      slot: "operation"
    }
  ];

  const stockcolumns: TableColumnList = [
    {
      type: "expand",
      slot: "expand",
      fixed: "left",
      width: "30px"
    },
    {
      label: "备货订单号",
      prop: "purchaseOrderCode",
      minWidth: 180
    },
    {
      label: "供应商名称",
      prop: "supplierName",
      minWidth: 200
    },
    {
      label: "状态",
      prop: "orderStatus",
      minWidth: 100,
      cellRenderer: ({ row }) => (
        <DictTag
          dict-type="PURCHASE_STATUS"
          type={
            row.orderStatus == 1
              ? "warning"
              : row.orderStatus == 2
                ? "success"
                : row.orderStatus == 3
                  ? "primary"
                  : row.orderStatus == 4
                    ? "info"
                    : "success"
          }
          dict-value={row.orderStatus}
        />
      )
    },
    {
      label: "备货总金额",
      prop: "orderPrice",
      minWidth: 120,
      cellRenderer: ({ row }) => <span>{dealDataExcept(row.orderPrice)}</span>
    },
    {
      label: "备货商品总数",
      prop: "orderNum",
      minWidth: 120
    },
    {
      label: "到货仓库",
      prop: "depositoryName",
      minWidth: 200,
      showOverflowTooltip: true
    }
  ];

  const stockChildColumns: TableColumnList = [
    {
      label: "商品名称/规格名称",
      prop: "specName",
      width: 200,
      align: "left",
      // slot: "specName",
      cellRenderer: goodsNameRend
    },
    {
      label: "商品编码/规格编码",
      prop: "specCode",
      align: "left",
      width: 150,
      // slot: "specCode",
      cellRenderer: goodsCodeRend
    },
    {
      label: "商品类型",
      prop: "goodsType",
      minWidth: 100,
      cellRenderer: ({ row }) => (
        <DictTag dict-type="PRODUCT_TYPE" dict-value={row.goodsType} />
      )
    },
    {
      label: "备货商品数量",
      prop: "amount",
      minWidth: 120
    },
    {
      label: "已入库商品数量",
      prop: "storeAmount",
      minWidth: 120
    },
    {
      label: "待入库商品数量",
      prop: "storeAmount",
      minWidth: 120,
      formatter: row => getDrkCount(row)
    },
    {
      label: "实际入库商品数量",
      prop: "rksl",
      width: 150,
      cellRenderer: ({ row }) => (
        <el-input-number
          min={1}
          step={1}
          step-strictly
          clearable
          placeholder="请输入"
          v-model={row.rksl}
          style="width: 100%"
        />
      )
    }
  ];

  return {
    directcolumns,
    directChildColumns,
    stockcolumns,
    stockChildColumns
  };
}
